' got these scripts from the active directory cookbook.
' dumps all users with a mail attribute set in active directory
' takes what is left of the @ symbol.
' may or may not be the same as their login name.
' sets a golbal password for everyone.

' pipe this to a file to get your user list for upload to
' google apps.


' ------ SCRIPT CONFIGURATION ------
strDomainDN = "dc=some,dc=org"    ' e.g. dc=rallencorp,dc=com
strPass = "GooglePassword1"
' ------ END CONFIGURATION ---------

strBase   =  "<LDAP://" & strDomainDN & ">;"
' To search the whole forest using the global catalog, uncomment the following line:
' strBase   =  "<GC://" & strDomainDN & ">;"

strFilter = "(&(objectclass=user)(objectcategory=person));" 
strAttrs  = "mail,givenName,sn;"
strScope  = "subtree"

set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
wscript.echo "username, last name, first name, password"
objRS.MoveFirst
while Not objRS.EOF
  if len(objRS.Fields(0).Value) > 0 Then
     username = left(objRS.Fields(0).Value, instr(objRS.Fields(0).Value, "@") -1) 
     Wscript.Echo username & ", " & objRS.Fields(1).Value & ", " & objRS.Fields(2).Value & "," & strPass 
  end if
  objRS.MoveNext
wend
